// spu管理的模块
import request from '@/utils/bradn-request'

// 获取spu管理列表数据 GET /admin/product/{page}/{limit} 还需要携带三级分类的id
export const reqSpuList = (page, limit, category3Id) => request({
    url: `/admin/product/${page}/${limit}`,
    method: 'get',
    params: { category3Id }
})

// 获取spu信息 GET /admin/product/getSpuById/{spuId}
export const reqSpu = (spuId) => request.get(`/admin/product/getSpuById/${spuId}`)

// 获取品牌信息 GET /admin/product/baseTrademark/getTrademarkList
export const reqTrademarkList = () => request.get('/admin/product/baseTrademark/getTrademarkList')

// 获取spu图片的接口 GET /admin/product/spuImageList/{spuId}
export const reqSpuImageList = (spuId) => request.get(`/admin/product/spuImageList/${spuId}`)

// 获取平台全部的销售属性 /admin/product/baseSaleAttrList
export const reqBaseSaleAttrList = () => request.get('/admin/product/baseSaleAttrList')

// 修改spu||添加spu：对于修改或添加，携带给服务器参数大致一样的，唯一区别就是携带的参数是否带id
export const reqAddOrUpdateSpu = (spuInfo) => {
    // 携带的参数有id---修改spu
    if (spuInfo.id) {
        return request({
            url: '/admin/product/updateSpuInfo',
            method: 'post',
            data: spuInfo
        })
    } else {
        // 携带的参数没有id---添加spu
        return request({
            url: '/admin/product/saveSpuInfo',
            method: 'post',
            data: spuInfo
        })
    }
}

// 删除spu DELETE /admin/product/deleteSpu/{spuId}
export const reqDeleteSpu = (spuId) => request({ url: `/admin/product/deleteSpu/${spuId}`, method: 'delete' })


// 获取销售属性的属性 /admin/product/spuSaleAttrList/{spuId}
export const reqSpuSaleAttrList = (spuId) => request.get(`/admin/product/spuSaleAttrList/${spuId}`)

// 获取平台属性的数据 /admin/product/attrInfoList/{category1Id}/{category2Id}/{category3Id}
export const reqAttrInfoList = (category1Id, category2Id, category3Id) => request.get(`admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`)

// 添加sku /admin/product/saveSkuInfo post
export const reqAddSku = (data) => request({
    url: "/admin/product/saveSkuInfo",
    method: 'post',
    data
})

// 查看SKU列表 GET /admin/product/findBySpuId/{spuId}
export const reqSkuList = (spuId) => request.get(`/admin/product/findBySpuId/${spuId}`)